// App.tsx
import { lazy } from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom";

const App = () => {
    const pages = import.meta.glob("./pages/**/*.tsx");

    return (
        <BrowserRouter>
            <Routes>
                {Object.keys(pages).map((path) => {
                    const name = path.match(/\.\/pages\/(.*)\.tsx/)![1];
                    const PageComponent = lazy(() => pages[path]());
                    return <Route key={path} path={`/${name}`} element={<PageComponent />} />;
                })}
                <Route path="*" element={<h1>404 - Page Not Found</h1>} />
            </Routes>
        </BrowserRouter>
    );
};

export default App;
